#ifndef TASK_H
#define TASK_H


struct Task
{
public:	
	enum State
	{
		waiting,
		swapping,
		active,
		complete
	};

	int cyclesNeeded,	//Technically, this is inaccurate, we're measuring in ms, not cycles. We'll just assume a 1 kHz processor.
		cyclesCompleted,
		cyclesInCore,//used in round robin. it is incremented if bActive is true and used to compare against RRQuantum in Scsheduler
		cyclesWaited,
		swapCounter;
	State taskState;
	
	Task(){};
	Task(int needed):
		taskState(waiting),
		cyclesNeeded(needed),
		cyclesCompleted(0),
		cyclesInCore(0),
		cyclesWaited(0),
		swapCounter(0)
	{
	};

	void runCycle()
	{
		if(taskState != complete)
		{
			if(taskState == active)
			{
				++cyclesCompleted;
				if(cyclesCompleted >= cyclesNeeded) taskState = complete;
			}
			else if(taskState == waiting)
			{
				++cyclesWaited;
			}
			else
			{
				++cyclesWaited;
				--swapCounter;
				if(swapCounter <= 0) taskState = active;
			}
		}
	}

	friend class Scheduler;
};

#endif
